//
//  ColorExtension.swift
//  FoundationsAppCode
//
//  Created by Erickson on 16/3/18.
//  Copyright © 2016年 paiyipai. All rights reserved.
//

import Foundation
import UIKit



extension UIColor {
    convenience init(hex: Int) {
        let components = (
            R: CGFloat((hex >> 16) & 0xff) / 255,
            G: CGFloat((hex >> 08) & 0xff) / 255,
            B: CGFloat((hex >> 00) & 0xff) / 255
        )
        
        self.init(red: components.R, green: components.G, blue: components.B, alpha: 1)
    }
    
    convenience init(hexa: Int,alpha:CGFloat) {
        let components = (
            R: CGFloat((hexa >> 16) & 0xff) / 255,
            G: CGFloat((hexa >> 08) & 0xff) / 255,
            B: CGFloat((hexa >> 00) & 0xff) / 255
        )
        
        self.init(red: components.R, green: components.G, blue: components.B, alpha: alpha)
    }
}

extension CGColor {
    class func colorWithHex(_ hex: Int) -> CGColor {
        return UIColor(hex: hex).cgColor
    }
}


extension UIColor {
    static var loginBackgroundColor: UIColor {
        get {
            return UIColor(hex: 0xf8f8f8)
        }
    }
    static var loginCellFontColor: UIColor {
        get {
            return UIColor(hex:0x666666)
        }
    }
    static var cellSeparatorColor: UIColor {
        get {
            return UIColor(red:0.88, green:0.87, blue:0.89, alpha:1)
        }
    }
}

extension UIColor{
    class func imageWithColor(_ color:UIColor,size:CGSize)->UIImage{
        let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context!.setFillColor(color.cgColor)
        context!.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image!
        
    }
    
}
